#!/usr/bin/env python
# encoding: utf-8
'''
@author: 李勇
@contact: 13732546017@163.com
@software: garner
@file: Read_file.py
@time: 2020-01-03 20:01
@desc:
'''
import pymysql
from tools.Read_file import *

data_base = Read_file("Data_based_config.yaml")

def Con_based(based_name=None):

    if based_name is None:
        return 'data_name is None'
    data_info = data_base[based_name]

    if 'port' not in data_info.keys():
        db = pymysql.connect(data_info["host"], data_info["user"], data_info["pass"], data_info["based_name"],
                             charset=data_info["charset"])
        return db
    else:
        data_info = data_base[based_name]
        db = pymysql.connect(host=data_info["host"], user=data_info["user"], password=data_info["pass"], database=data_info["based_name"],
                             charset=data_info["charset"], port=data_info['port'])
        return db



